<?php
class C_harsat extends CI_Controller {
	function __construct(){
		parent::__construct();
		checkLogin();
		$this->load->model('m_harsat');
	}
	function index(){
		$task = secure_post('task');
		switch($task){
			case 'LIST' :
				$this->_list();
				break;
			case 'INSERT' :
				$this->_insert();
				break;
			case 'UPDATE' :
				$this->_update();
				break;
			case 'DELETE' :
				$this->_delete();
				break;
			case 'DEACTIVATE' :
				$this->_deactivate();
				break;
			default :
				$this->load->view('app/v_harsat');
		}
	}
	
	function _list(){
		$data['page'] = numeric_post("page");
		$data['rows'] = numeric_post("rows");
		$data['t_monitor_id'] = nosql_post("t_monitor_id");
		$data['harsat_ket'] = nosql_post("harsat_ket");
		$data['harsat_satuan'] = nosql_post("harsat_satuan");
		$data['harsat_nilai'] = nosql_post("harsat_nilai");
		echo $this->m_harsat->_list($data);
	}
	
	function _insert(){
		$data = array(
			't_monitor_id' => $this->input->post('t_monitor_id'), 
			'harsat_ket' => $this->input->post('harsat_ket'), 
			'harsat_satuan' => $this->input->post('harsat_satuan'), 
			'harsat_nilai' => $this->input->post('harsat_nilai'), 
			  
			'harsat_insert_user'	=>$_SESSION[SESSION_USERID],
			'harsat_insert_date'=> date("Y-m-d h:i:s"));
		$this->m_harsat->_insert($data);
		echo 1;
	}
	
	function _update(){
		$harsat_id = $this->input->post('harsat_id');
		$data = array(
			't_monitor_id' => $this->input->post('t_monitor_id'), 
			'harsat_ket' => $this->input->post('harsat_ket'), 
			'harsat_satuan' => $this->input->post('harsat_satuan'), 
			'harsat_nilai' => $this->input->post('harsat_nilai'), 
			
			'harsat_update_user'	=> $_SESSION[SESSION_USERID],
			'harsat_update_date'=> date("Y-m-d h:i:s"));
		$this->m_harsat->_update($data,$harsat_id);
		echo 1;
 	}
	
	function _delete(){
		$harsat_id= $this->input->post('harsat_id');
		$this->m_harsat->_delete($harsat_id);
		echo 1;
	}
	
	function _deactivate(){
		$harsat_id= $this->input->post('harsat_id');
		$data = array(
			'harsat_active' => 'n'
		);
		$this->m_harsat->_deactivate($data,$harsat_id);
		echo 1;
	}
}